import {
	defineStore
} from 'pinia';
import {
	toGetServiceList

} from "@/utils/request/service.js"
import moment from "moment"
export const useServiceStore = defineStore('service', {
	state: () => {
		return {
			status: {
				code: "",
				msg: ""
			},
			serviceList: []

		};
	},
	// 也可以这样定义
	// state: () => ({ count: 0 })
	actions: {
		//获取服务通知
		async getServiceList(userId) {
			try {
				this.serviceList = []
				const res = await toGetServiceList(userId);
				this.status.code = res.code;
				this.status.msg = res.msg;
				if (res.code == "200") {
					res.data.forEach((p) => {
						p.serveTime = moment(p.serveTime).format("YYYY-MM-DD HH:mm:ss")
						if (p.status == "0") {
							p.status = "发布成功"
						} else {
							p.status = "删除成功"
						}
						this.serviceList.unshift(p);
					})
				}
			} catch (err) {
				this.status.code = "405";
				this.status.msg = "网络不好，请稍后重试";
			}
		},
	}
});